﻿using OnlineMealOrdering.Extends;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Web;
using log4net;

namespace OnlineMealOrdering.Common
{
    public static class SiteHelper
    {
        public static CustomIdentity CurrentUser
        {
            get
            {
                CustomIdentity identity = null;
                if (HttpContext.Current.User.Identity != null)
                    identity = HttpContext.Current.User.Identity as CustomIdentity;

                if (identity == null)
                {
                    //没有登录
                    throw BusinessException.Create("你没有登录");
                }

                return identity;
            }
        }

        public const int PageSizeGlobal = 2;
        public const int PageSizeDataList = 8;

        public static readonly string WebServerRootPath = HttpContext.Current.Server.MapPath("~/");

    }

    public static class WebLog<T>
    {
        static ILog Log = log4net.LogManager.GetLogger(typeof(T));

        public static void AddLog(string msg, params object[] args)
        {
            Log.Error(string.Format(msg, args));
        }

        public static void AddLog(string msg)
        {
            Log.Error(msg);
        }
        public static void AddLog(string msg, Exception e)
        {
            Log.Error(msg, e);
        }
    }
}